<template>
    <div>
        <!-- <Row>
             <Input v-model="nameQuery" placeholder="请输入姓名..." style="width: 200px"/>
             <Input v-model="accountPhone" placeholder="请输入手机号码..." style="width: 200px"/>
             <Button @click="handleRead" type="primary" icon="search">搜索</Button>
             <Button @click="handleAdd">添加</Button>
         </Row>-->

        <Row class="margin-top-10 searchable-table-con1">
            <Table border  refs="models" :data="records" @on-delete="handleDelete" :columns="columns"></Table>
        </Row>
        <Row class="margin-top-10 searchable-table-con1">
            <Page :total="totalCount" :page-size="size" show-total @on-change="changePage"></Page>
        </Row>
    </div>
</template>

<script type="text/ecmascript-6">
    import api  from '../../libs/api'
    import util from "../../libs/util"
    export default {
        name: 'processDefines',
        data () {
            return {
                records: [],
                current: 1,
                size: 10,
                totalCount: 0,
                totalPage: 0,
                columns: [
                    {
                        title: '流程定义ID',
                        key: 'id'
                    },
                    {
                        title: '流程定义名称',
                        key: 'name'
                    },
                    {
                        title: '流程定义KEY',
                        key: 'key'
                    },
                    {
                        title: '版本号',
                        key: 'version'
                    },
                    {
                        title: '规则文件名称',
                        key: 'resourceName'
                    },
                    {
                        title: '规则图片名称',
                        key: 'diagramResourceName'
                    },
                    {
                        title: '部署ID',
                        key: 'deploymentId'
                    },
                    {
                        title: '操作',
                        align: 'center',
                        width: 200,
                        key: 'handle',
                        render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                           util.openUrl(api.baseURL+api.activity.processDefines.view.replace("{deploymentId}",params.row.deploymentId).
                                               replace("{diagramResourceName}",params.row.diagramResourceName));
                                        }
                                    }
                                }, '查看流程图')
                            ]);
                        }
                    }
                ]
            }
        },
        methods: {
            handleRead(){
                let data = {};
                data.current = this.current;
                data.size = this.size;
                this.$get(api.activity.processDefines.base, data).then(response => {
                    this.totalPage = this.util.calTotalPage(response.obj.total, this.size);
                    this.totalCount = response.obj.total;
                    this.records = [];
                    for (let i in response.obj.records) {
                        this.records.push(response.obj.records[i])
                    }
                });
            },
            handleDelete (modelId) {
                this.$delete(api.activity.models.base+"/"+modelId,null).then(response=>{
                    this.handleRead();
                });
            },
            handleDeploy(modelId){
                this.$post(api.activity.models.deploy.replace("{id}",modelId),null).then(response=>{
                    this.handleRead();
                });
            },
            changePage(index){
                this.current = index;
                this.handleRead();
            }
        },
        created(){
            this.handleRead();
        }
    }
</script>

<style>

</style>
